import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;


public class Client 
{
	public static void main(String[] pArgs) 
	{
		if(pArgs.length<3)
		{
			System.out.println("usage: java Client host port boardnum");
			return;
		}
	
		try
		{
			Socket lSocket=new Socket(pArgs[0],Integer.parseInt(pArgs[1]));
			PrintWriter lOut=new PrintWriter(lSocket.getOutputStream());
			BufferedReader lIn=new BufferedReader(new InputStreamReader(lSocket.getInputStream()));
			BufferedReader bufread = new BufferedReader(new FileReader(new File("C:\\Users\\Jonas\\Javaprograms\\SkyNet2.0 - Sokoban\\sokobanEasy.txt")));
			String[] strAry = null;
			long start, stop;
			
            lOut.println(pArgs[2]);
            lOut.flush();

            String lLine=lIn.readLine();

            //read number of rows
//            int lNumRows=Integer.parseInt(lLine);
            int lNumRows = 4;
            strAry = new String[lNumRows];
            
//            for(int rounds = lNumRows; rounds>0; rounds--) {
//            	strAry[rounds] = lIn.readLine();
//            }
//            
            
            char[][] board = null;

            boolean first = true;
            
            //read each row
            for(int i=0;i<lNumRows;i++)
            {
                //lLine=lIn.readLine();
//                System.out.println(lLine);
                lLine = bufread.readLine();
                if ( first )
                {
                	board = new char[ lLine.length() ][ lNumRows ];
                	first = false;
                }
                
                for ( int n = 0; n < lLine.length(); n++ )
                {
                	 board[ n ][ i ] =  lLine.charAt(n);   
                }
            }
                
            
           
//            UsedSolutionFinder uSF = new UsedSolutionFinder();
            
            Board ourBoard = new Board( board );
            Search s = new Search();
            
            
            
//            String lMySol = findSolution( board );
//            String lMySol = solution.FindSolution(ourBoard);
            start = System.currentTimeMillis();
            String lMySol = s.bruteSearch(ourBoard);
            stop = System.currentTimeMillis();
           
            System.out.println( lMySol );

            System.out.println(stop-start+ "ms");
            
            //send the solution to the server
            lOut.println(lMySol);
            lOut.flush();
    
            //read answer from the server
            lLine=lIn.readLine();
    
//            System.out.println(lLine);
		}
		catch(Throwable t)
		{
			t.printStackTrace();
		}
	}

}
